package com.supkong.java.optional;

import com.supkong.java.optional.bean.User;

import java.util.Optional;

/**
 * @program: jdk8-learning-example
 * @author: Kong
 * @create: 2019-10-31 17:49
 * @description:
 **/
public class OptionalTest {
    public static void main(String[] args) {
        UserService userService =  new UserService();
        User user = new User();
        user.setId("1232");
        user.setRoleId("rol111");
        user.setName("呵呵");
        //通常情况下
        userService.bindUserRole(user);
        //使用Jdk 8 Optional
       Optional<String> opt =  Optional.ofNullable(user).map(User::getRoleId);
       if(opt.isPresent()){
           System.out.println("!!!");
       }
    }
}
